﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace HangerSupport
{
	public partial class DlgHSDistSet : System.Windows.Forms.Form
	{
		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		private void SetFocusToRevit()
		{
			int wMsg = 7;
			DlgHSDistSet.SendMessage(HSManage._hWndRevit.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
		}

		[DllImport("user32.dll")]
		public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		private void CancelRevitOperate()
		{
			byte bVk = 27;
			int dwFlags = 0;
			int dwFlags2 = 2;
			DlgHSDistSet.keybd_event(bVk, 0, dwFlags, 0);
			DlgHSDistSet.keybd_event(bVk, 0, dwFlags2, 0);
		}

		private void DlgHSDistSet_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.SetFocusToRevit();
			this.m_bCloseByUser = true;
			DlgHSDistSet.g_Dlg_X = base.Location.X;
			DlgHSDistSet.g_Dlg_Y = base.Location.Y;
		}

		private void DlgHSDistSet_Load(object sender, EventArgs e)
		{
			base.Location = new System.Drawing.Point(DlgHSDistSet.g_Dlg_X, DlgHSDistSet.g_Dlg_Y);
		}

		private void DlgHSDistSet_MouseLeave(object sender, EventArgs e)
		{
			bool flag = !base.ClientRectangle.Contains(base.PointToClient(Cursor.Position));
			if (flag)
			{
				double num = 0.0;
				bool flag2 = !this.IsValidDistStart(ref num) || !this.IsValidDistSeparation(ref num);
				if (!flag2)
				{
					this.SetFocusToRevit();
				}
			}
			else
			{
				base.Focus();
			}
		}

		public DlgHSDistSet()
		{
			this.InitializeComponent();
			YJKProcessTools hyprocessTools = new YJKProcessTools();
			hyprocessTools.ShowInTaskbarChange(this);
		}

		public DlgHSDistSet(double dDistStart, double dDistSeparation)
		{
			this.InitializeComponent();
			YJKProcessTools hyprocessTools = new YJKProcessTools();
			hyprocessTools.ShowInTaskbarChange(this);
			dDistStart = Utils.DoublePrecision(dDistStart, 1);
			dDistSeparation = Utils.DoublePrecision(dDistSeparation, 1);
			this.txtDistStart.Text = dDistStart.ToString();
			this.txtDistSeparation.Text = dDistSeparation.ToString();
			double num = 1.0;
			double num2 = 1.0;
			WinDPIManager.GetWinFormXYDpi(ref num, ref num2);
			this.label2.Location = new System.Drawing.Point(Convert.ToInt32(30.0 * num), Convert.ToInt32(43.0 * num2));
			this.txtDistSeparation.Location = new System.Drawing.Point(Convert.ToInt32(99.0 * num), Convert.ToInt32(40.0 * num2));
			this.label1.Location = new System.Drawing.Point(Convert.ToInt32(6.0 * num), Convert.ToInt32(67.0 * num2));
			this.txtDistStart.Location = new System.Drawing.Point(Convert.ToInt32(99.0 * num), Convert.ToInt32(64.0 * num2));
		}

		public DlgHSDistSet(double dDistStart, double dDistSeparation, int count)
		{
			this.InitializeComponent();
			YJKProcessTools hyprocessTools = new YJKProcessTools();
			hyprocessTools.ShowInTaskbarChange(this);
			dDistStart = Utils.DoublePrecision(dDistStart, 1);
			dDistSeparation = Utils.DoublePrecision(dDistSeparation, 1);
			this.txtDistStart.Text = dDistStart.ToString();
			this.txtDistSeparation.Text = dDistSeparation.ToString();
			this.radioButton1.Visible = true;
			this.radioButton2.Visible = true;
			bool flag = count > 1;
			if (flag)
			{
				this.radioButton1.Enabled = false;
				this.radioButton1.Checked = false;
				this.radioButton2.Checked = true;
				this.txtDistSeparation.Enabled = true;
			}
			else
			{
				this.radioButton1.Checked = true;
				this.radioButton2.Checked = false;
				this.txtDistSeparation.Enabled = false;
			}
			double num = 1.0;
			double num2 = 1.0;
			WinDPIManager.GetWinFormXYDpi(ref num, ref num2);
			this.label2.Location = new System.Drawing.Point(Convert.ToInt32(30.0 * num), Convert.ToInt32(43.0 * num2));
			this.txtDistSeparation.Location = new System.Drawing.Point(Convert.ToInt32(99.0 * num), Convert.ToInt32(40.0 * num2));
			this.label1.Location = new System.Drawing.Point(Convert.ToInt32(6.0 * num), Convert.ToInt32(67.0 * num2));
			this.txtDistStart.Location = new System.Drawing.Point(Convert.ToInt32(99.0 * num), Convert.ToInt32(64.0 * num2));
		}

		public bool IsValidDistStart(ref double dVal)
		{
			bool flag = !Utils.IsStringDouble(this.txtDistStart.Text, ref dVal) || dVal < 0.0;
			bool result;
			if (flag)
			{
				Utils.MessageBox("输入起始距离值有误");
				dVal = 0.0;
				result = false;
			}
			else
			{
				result = true;
			}
			return result;
		}

		public bool IsValidDistSeparation(ref double dVal)
		{
			bool flag = !Utils.IsStringDouble(this.txtDistSeparation.Text, ref dVal) || dVal < 1.0;
			bool result;
			if (flag)
			{
				Utils.MessageBox("输入分布间距值有误");
				dVal = 0.0;
				result = false;
			}
			else
			{
				result = true;
			}
			return result;
		}

		public double GetDistStart()
		{
			double result = 0.0;
			this.IsValidDistStart(ref result);
			return result;
		}

		public double GetDistSeparation()
		{
			double result = 0.0;
			this.IsValidDistSeparation(ref result);
			return result;
		}

		public bool GetIsAuto()
		{
			return this.radioButton1.Checked;
		}

		private void radioButton2_CheckedChanged(object sender, EventArgs e)
		{
			this.txtDistSeparation.Enabled = this.radioButton2.Checked;
		}

		private static int g_Dlg_X = 10;

		private static int g_Dlg_Y = 10;

		public bool m_bCloseByUser = false;
	}
}
